//设置cookies
function setCookie(name, value) {
    var exp = new Date();
    exp.setTime(exp.getTime() + 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}
//获取cookies
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) return unescape(arr[2]);
    else return null;
}
//删除cookies
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1000);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
//获取URL参数
function getQS(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return (r[2]);
    return null;
}

//是否为正整数 
function is11Num(s) {
    var re = /^[1-9]\d{10}$/;
    return re.test(s)
}

//身份证获取性别
function Csex(sfz) {
    var num;
    if (sfz.length == 18) {
        num = sfz.substr(-2, 1);
    }
    else {
        num = sfz.substr(-1);
    }
    return num % 2;
}

/** 检查号码是否符合规范，包括长度，类型 **/
function isCardNo(card) {
//身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
    var reg = /(^\d{17}(\d|X)$)/;
    return reg.test(card.toUpperCase());
};

//获取预约时间的当前时间
function plantime() {
    var myDate = new Date();
    myDate = myDate.getFullYear() + "-" + ("0" + parseInt(myDate.getMonth() + 1)).substr(-2) + "-" + ("0" + parseInt(myDate.getDate())).substr(-2) + "T" + (myDate.getHours() - 0 + 2) + ":" + ("0" + myDate.getMinutes()).substr(-2) + ":" + ("0" + myDate.getSeconds()).substr(-2);
    return myDate;
}
//判断时间是否符合9点到20点
function rulestime(a) {
    var times = false;
    a = a.split(" ");
    var Hours = a[1].substr(0, 2);
    var Minutes = a[1].substr(3, 2);
    var myDate = new Date();
    thisHours = myDate.getHours() - 0 + 2;
    var ymd = myDate.getFullYear() + "-" + ("0" + (myDate.getMonth() - 0 + 1)).substr(-2) + "-" + ("0" + myDate.getDate()).substr(-2);

    if (a[0] == ymd) {
        if (Hours >= thisHours && Hours >= 9 && Hours < 20) {
            times = true;
            //console.log(0)
        }
    }
    else {
        if (Date.parse(a[0]) > Date.parse(myDate) && Hours >= 9 && Hours < 20) {
            times = true;
            //console.log(1)
        }
    }

    return times;
}

//获取资费类型
function getIspList(a) {
    $.ajax({
        type: "get",
        url: aurl + "/ispManager/WebTool/getIspList/" + a,
        async: true,
        dataType: 'json',
        timeout: 5000,
        contentType: 'application/text;charset=UTF-8',
        success: function (data) {
            var selects = data.JsonArray;
            var count = selects.length;

            $(".weui_select.lei").html($(".weui_select.lei option").eq(0));
            for (var i = 0; i < count; i++) {
                $(".weui_select.lei").append("<option value='" + selects[i].Ispid + "'>" + selects[i].Ispname + "</option>")
            }
        }
    });
}

//解析JSON字符串
function parseJSON(a) {
    return eval("(" + a + ")")
}

function ops(a) {
    a.not(function () {
        return !this.selected
    })
}

Array.prototype.unique3 = function () {
    var res = [];
    var json = {};
    for (var i = 0; i < this.length; i++) {
        if (!json[this[i]]) {
            res.push(this[i]);
            json[this[i]] = 1;
        }
    }
    return res;
}


//获取个人信息
function getCustomerList(openid, callback) {
    $.ajax({
        type: "get",
        url: aurl + "/ispManager/WebTool/getCustomerList/" + openid,
        async: true,
        dataType: 'json',
        contentType: 'application/text;charset=UTF-8',
        success: function (data) {

            callback(data)

            console.log(data);
        }
    });
}

//获取个人信息END

function alert2(a) {
    //初始化
    if ($("#dialog2").length == 0) {
        //<!--BEGIN dialog2-->
        var alerts = "";
        alerts = alerts + "<div class=\"weui_dialog_alert\" id=\"dialog2\" style=\"display:none;\">";
        alerts = alerts + "<div class=\"weui_mask\"></div>";
        alerts = alerts + "<div class=\"weui_dialog\">";
        alerts = alerts + "<div class=\"weui_dialog_hd\"><strong class=\"weui_dialog_title\">提示</strong></div>";
        alerts = alerts + "<div class=\"weui_dialog_bd\">服务器错误！</div>";
        alerts = alerts + "<div class=\"weui_dialog_ft\">";
        alerts = alerts + "<a href=\"javascript:;\" class=\"weui_btn_dialog primary\">确定</a>";
        alerts = alerts + "</div></div></div>";
        //<!--END dialog2-->
        $("body").append(alerts);
    }

    $('#dialog2 .weui_btn_dialog').bind('click', function () {
        $('#dialog2').hide();
    });

    $('#dialog2 .weui_dialog_bd').html(a);
    $('#dialog2').show();
    return false;
}

function loadings(a) {
    if ($("#loadingToast").length == 0) {

        var loading = "<div id=\"loadingToast\" class=\"weui_loading_toast\" style=\"display: none;\">";
        loading = loading + "<div class=\"weui_mask_transparent\"></div>";
        loading = loading + "<div class=\"weui_toast\">";
        loading = loading + "<div class=\"weui_loading\">";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_0\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_1\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_2\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_3\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_4\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_5\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_6\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_7\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_8\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_9\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_10\"></div>";
        loading = loading + "<div class=\"weui_loading_leaf weui_loading_leaf_11\"></div>";
        loading = loading + "</div><p class=\"weui_toast_content\">" + a + "</p>";
        loading = loading + "</div></div>";

        $("body").append(loading);
    }
    else {
        $(".weui_toast_content").html(a)
    }
    $("#loadingToast").show();

}

var s = location.href.toLowerCase();
s = s.slice(s.lastIndexOf("/") + 1);
if ((s.indexOf("installation_list.") != -1) || (s.indexOf("pay.") != -1) || (s.indexOf("installation.") != -1) || (s.indexOf("repair.") != -1)) {
    if ((getQS('rnd') == null)) {
        if (s.indexOf("?") != -1) {
            window.location = window.location.href + "&rnd=" + Math.random();
        }
    }
}

////验证是否登录
var openid = null;

if (getQS('openid') == null) {

    if (getCookie('openid') == null) {
        alert2("openid未传递！:");
    }
    else {
        if (getCookie('openid').length != 28) {
            alert2("openid传递的不正确！<br>getCookie(openid):" + getCookie('openid') + "<br>" + document.URL);
        }
        else {
            openid = getCookie('openid');
            setCookie("openid", openid);
        }
    }
}

else {
    if (getQS('openid').length != 28) {
        alert2("openid获取失败！<br>getQS('openid'):" + getQS('openid') + "<br>" + document.URL);
    }
    else {
        openid = getQS('openid');
        setCookie("openid", openid);
    }
}
var aurl = "http:\/\/wx.4001398890.com";

//ajax初始参数
var xv_ajax = {};
xv_ajax.s_url = "\/ispManager\/ShoppingWebView\/";
xv_ajax.type = "post";//发送的请求方式
xv_ajax.async = true;//是否同步
xv_ajax.dataType = 'json';//回传为什么格式
xv_ajax.contentType = 'application/text;charset=UTF-8';//发送参数的编码
xv_ajax.timeout = 5000;//超时时间
xv_ajax.beforeSend = function (XMLHttpRequest)//完成后的操作
{
}
xv_ajax.complete = function (XMLHttpRequest, status)//完成后的操作
{
    if (status == 'timeout') {
        alert2("请求超时请返回重试!");
    }
};
//ajax初始参数end

//Cookie操作函,数不依赖其他JS库 
xv_Cookie = {};
xv_Cookie.version = "1.0,估计不会再修改此版本"
xv_Cookie.set = function (name, value) {
    var exp = new Date();
    exp.setTime(exp.getTime() + 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}
xv_Cookie.get = function (name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) return unescape(arr[2]);
    else return null;
}
xv_Cookie.del = function (name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1000);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
//Cookie操作函数

//自定义操作函数，不涉及业务,不依赖其他JS库 
xv_f = {};
//获取URL参数
xv_f.getQS = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return (r[2]);
    return null;
}
//判断是否为正整数
xv_f.isNum = function (s) {
    var re = /^[0-9]*[1-9][0-9]*$/;
    return re.test(s)
}

xv_f.imgurl = "/upload/attachedimage/";

xv_f.toDecimal2 = function (x) {
    var f = parseFloat(x);
    if (isNaN(f)) {
        return false;
    }
    var f = Math.round(x * 100) / 100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + 2) {
        s += '0';
    }
    return s;
}

if (xv_Cookie.get("addressId") != null) {
    xv_Cookie.set("addressId", xv_Cookie.get("addressId"))
}
if (xv_Cookie.get("addressDist") != null) {
    xv_Cookie.set("addressDist", xv_Cookie.get("addressDist"))
}
if (xv_Cookie.get("addressInfo") != null) {
    xv_Cookie.set("addressInfo", xv_Cookie.get("addressInfo"))
}

var Table = {};
Table.META_TYPE = "meta_type";
Table.META_DATA = "meta_data";
Table.META_DATA_DICTIONARY = "meta_date_dictionary";
Table.META_DETAILED = "meta_detailed";
Table.META_DETAILED_COLUMN = "meta_detailed_column";
Table.META_FILTER = "meta_filter";
Table.META_LIST = "meta_list";
Table.META_MAIN = "meta_main";
Table.META_MODEL = "meta_model";
Table.META_SOURCE = "meta_source";
Table.META_SOURCE_COLUMN = "meta_source_column";
Table.META_DATA_BASE = "meta_data_base";
Table.META_DATA_TABLE = "meta_data_table";